﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MyDateTimePicker
{
    public partial class MyDateTimePicker : UserControl
    {
        public MyDateTimePicker()
        {
            InitializeComponent();
        }

        protected string dateText = "";
        [Category("自定义"), Description("显示文本")]
        [Browsable(true)]
        public string Text
        {
            get
            {
                dateText = myTextBox.Text;
                return dateText;
            }
            set
            {
                dateText = value;
                myTextBox.Text = dateText;
            }
        }

        private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
        {
            myTextBox.Text = dateTimePicker.Value.ToLongDateString();
        }

        private void MyDateTimePicker_Resize(object sender, EventArgs e)
        {
            myTextBox.Location = new Point(0, 0);
            myTextBox.Size = new Size(this.Size.Width, 20);
            myButton.Location = new Point(this.Size.Width - 19, 1);
        }

        [System.Runtime.InteropServices.DllImport("user32.dll")]
        static extern long SendMessage(IntPtr hWnd, uint Msg, uint wParam, int lParam);
        const int WM_SYSKEYDOWN = 0x0104, VK_DOWN = 0x28;

        private void myButton_Click(object sender, EventArgs e)
        {
            SendMessage(dateTimePicker.Handle, WM_SYSKEYDOWN, VK_DOWN, 0);
            
            
            bool b = dateTimePicker.Focus();
            Console.WriteLine("dateTimePicker 获取焦点 " + b );
        }

        private void dateTimePicker_DropDown(object sender, EventArgs e)
        {
            Console.WriteLine("dateTimePicker 下拉事件 ");
        }
    }
}
